package com.hyf.gateway.config;

import com.hyf.gateway.constants.CommonConstants;
import org.springframework.cloud.gateway.route.RouteLocator;
import org.springframework.cloud.gateway.route.builder.RouteLocatorBuilder;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author baB_hyf
 * @date 2021/07/13
 */
@Configuration
public class RouteConfiguration {

    @Bean
    public RouteLocator routeLocator(RouteLocatorBuilder builder) {
        return builder.routes()
                .route("proxy-web", predicate -> predicate.path("/" + CommonConstants.PASS_ID + "/web/**")
                        .filters(filter -> filter.rewritePath("/" + CommonConstants.PASS_ID + "/?(?<contextPath>.*)", "/$\\{contextPath}"))
                        .uri("http://127.0.0.1:8080"))
                .route("proxy-sso-web", predicate -> predicate.path("/" + CommonConstants.PASS_ID + "/sso-web/**")
                        .filters(filter -> filter.rewritePath("/" + CommonConstants.PASS_ID + "/?(?<contextPath>.*)", "/$\\{contextPath}"))
                        .uri("http://127.0.0.1:8081"))
                .build();

    }
}
